import java.util.Arrays;
public class Solution {
    static class Node{
        int val;
        Node next;
        Node(int val){
            this.val = val;
        }
    }

    public static Boolean haveCircle(Node head){
        if(head==null)
            return false;

        Node fast = head;
        Node low = head;
        while(low.next!=null && fast.next!=null && fast.next.next!=null){
            fast = fast.next.next;
            low = low.next;
            if(fast==low)
                return true;
        }
        return false;
    }
    public static void main(String args[]){
        Node head = new Node(0);
        Node node1 = new Node(1);
        Node node2 = new Node(2);
        Node node3 = new Node(3);
        Node node4 = new Node(4);
        Node node5 = new Node(5);
        Node node6 = new Node(6);
        Node node7 = new Node(7);
        Node node8 = new Node(8);
        head.next = node1;
        node1.next=node2;
        node2.next=node3;
        node3.next=node4;
        node4.next=node5;
        node5.next=node6;
        node6.next=node7;
        node7.next=node8;
//        node8.next=node5;
        boolean b = haveCircle(head);
        System.out.println(b);

    }



}

